import { toJS, observable, action } from 'mobx';
import { WeaTools } from 'ecCom';
import * as Apis from '../apis/sellChance';
import { WeaLocaleProvider } from 'ecCom';
import { message, Modal } from 'antd';

const getLabel = WeaLocaleProvider.getLabel;

export class SellChanceCarsAuthStore {
    @observable openAuth = false;
    @observable shareCondition = {};
    @observable dataSource = [];
    @observable selectIds = [];
    @observable sellChanceId = '';
    @observable shareHasRight = false;

    @action
    componentWillMount = (comObj) => {
      this.comObj = comObj;
      this.sellChanceId = this.comObj.props.params.sellChanceId;
    }

    @action
    componentDidMount = () => {
      this.getShareCondition();
      this.getShareList();
    }

    @action
    componentWillUnmount = () => {

    }

    @action
    openAuthForm = (bool) => {
      this.openAuth = bool;
    }
    @action
    getShareCondition = () => {
      const params = { showlevel: 1 };
      Apis.getShareForm(params).then((result) => {
        this.shareCondition = result.data;
      });
    }
    @action
    saveShareForm = (params) => {
      params.sellChance = this.sellChanceId;
      Apis.saveSellChanceAuth(params).then((result) => {
        if (result.status == 'success') {
          message.success(result.msgcode);
          this.getShareList();
        } else {
          message.error(result.msgcode);
        }
      });
    }
    @action
    getShareList = () => {
      Apis.getShareList({ sellChance: this.sellChanceId }).then((result) => {
        if (result.status == 'success') {
          this.dataSource = result.data;
        }
        this.shareHasRight = result.hasRight;
      });
    }

    @action
    getSelectIds = (ids = []) => {
      this.selectIds = ids;
    }
    @action
    deleteShareAuth = (param) => {
      const params = { ...param, sellChance: this.sellChanceId };
      const that = this;
      Modal.confirm({
        title: getLabel(15172, '系统提示'),
        content: getLabel(83600, '您确认要删除吗？'),
        okText: getLabel(33703, '确定'),
        cancelText: getLabel(201, '取消'),
        onOk() {
          Apis.deleteSellChanceAuths({ ...params }).then((result) => {
            if (result.status == 'success') {
              message.success(result.msgcode);
              that.getShareList();
            } else {
              message.error(result.msgcode);
            }
          });
        },
        onCancel() { },
      });
    }
}
